﻿using System;
using System.Collections.Generic;
using System.Text;

using Torch.WL.Entity.CleanChina;
using System.Data.SqlClient;
using System.Data;

namespace Torch.WL.DataAccess.CleanChina
{
    public class TbAdvertiseAccess
    {
        public TbAdvertiseAccess()
        {

        }


        public TbAdvertiseEntity GetCurrentAdvertise()
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from Tb_Advertise ");
            strSql.Append(" where adv_isCurrent=1 ");

            TbAdvertiseEntity model = new TbAdvertiseEntity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), null);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }



        private TbAdvertiseEntity DataRowToModel(DataRow row)
        {
            TbAdvertiseEntity model = new TbAdvertiseEntity();
            if (row != null)
            {
                if (row["advId"] != null && row["advId"].ToString() != "")
                {
                    model.advId = int.Parse(row["advId"].ToString());
                }
                if (row["adv_title"] != null)
                {
                    model.adv_title = row["adv_title"].ToString();
                }
                if (row["adv_img"] != null)
                {
                    model.adv_img = row["adv_img"].ToString();
                }
                if (row["adv_isCurrent"] != null && row["adv_isCurrent"].ToString() != "")
                {
                    model.adv_isCurrent = int.Parse(row["adv_isCurrent"].ToString());
                }
                if (row["createTime"] != null && row["createTime"].ToString() != "")
                {
                    model.createTime = DateTime.Parse(row["createTime"].ToString());
                }
            }
            return model;
        }


    }
}
